// pages/products_ detail/products_ detail.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    safeAreaTop: null,
    goods_Infor: [],
    amounts: 1,
    goods_id: 0,
    info: 0,




  },

  // swichNav: function(e) {
  //   console.log(e);
  //   var that = this;
  //   if (this.data.currentTab === e.target.dataset.current) {
  //     return false;
  //   } else {
  //     that.setData({
  //       currentTab: e.target.dataset.current,
  //     })
  //   }
  // },
  // swiperChange: function(e) {
  //   console.log(e);
  //   this.setData({
  //     currentTab: e.detail.current,
  //   })

  // },
  to_Retuen: function() {
    wx.switchTab({
      url: '/pages/main/main',
    })

  },

  unmberAdd: function(e) {

    const amounts = e.detail
    console.log(amounts)
    this.setData({
      amounts: e.detail


    })

  },

  toPurchase: function(e) {
    console.log(e)
    // const amounts = e.detail
    // const amounts = e.detail
    // const goods_id = getApp(goods_id)
    // console.log("累加的值",e.detail)
    const amounts = this.data.amounts;
    const id = this.data.goods_id;
    console.log(id)
    // id = 139 & amounts4=undefined



    console.log("数量", amounts)
    this.setData({
      id,
      amounts
    })

    wx.navigateTo({
      url: '/pages/order_detail/order_detail?id=' + id + '&amounts=' + amounts,
      // + "&amounts" + amounts


    })

  },
  clickme: function() {
    this.showModal();
  },
  showModal: function() {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function() {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  //隐藏对话框
  hideModal: function() {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function() {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  },
  // 加入购物车
  addTocar: function() {

    // console.log(id)
    // var info = 0
    // this.setData({
    //   info: info + 1
    // })
    const quantity = this.data.amounts
    const goods_id = this.data.goods_id

    console.log(quantity)
    console.log(goods_id)
    wx.request({

      url: 'https://ds.wyadmin.cn/api/membercart/cart_add',
      method: 'POST',
      data: {
        goods_id: goods_id,
        quantity: quantity
      },
      header: {
        'content-type': 'application/json',
        'X-DS-KEY': wx.getStorageSync('token')

      },
      success: res => {
        wx.showToast({
          title: '操作成功',
        })
        // wx.reLaunch({
        //   url: '/pages/main_shoping/main_shoping',
        // })
      }
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // const systemInfo = wx.getSystemInfoSync();
    // const boundingRect = wx.getMenuButtonBoundingClientRect();
    // console.log(boundingRect.left)
    // this.setData({
    //   safeAreaTop: systemInfo.safeArea.top,
    //   navPadding: systemInfo.windowWidth - boundingRect.left,
    //   navPaddingString: `padding: ${systemInfo.safeArea.top}px ${systemInfo.windowWidth - boundingRect.left}px 0`
    // })
    // var id = options.id;

    console.log("获取到的id", options.id)
    const goods_id = options.id
    wx.request({
      url: 'https://ds.wyadmin.cn/api/Goods/goods_detail',
      method: 'GET',
      data: {
        goods_name: '',
        goods_price: '',
        goods_img_480: '',

        goods_id: options.id

      },
      header: {
        'Content-Type': 'application/json'
      },
      success: res => {
        console.log(res)

        const goods_product = res.data.result;
        const goods_image = goods_product.goods_image;
        const goods_image_list = goods_image.split(',');
        console.log(goods_image_list)
        this.setData({
          goods_product,
          goods_image_list,
          goods_id

        })
      }
    })

    // console.log(two)




  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },


})